AreaCurd = Ext.extend(RockyTreeCurd, {
	baseUrl : 'area.action',
	winCfg : {
		autoScroll : false,
		layout : "fit",
		height : 360,
		width : 460,
		maximizable : true,
		title : "分类详细信息"
	},	
	closable : true,
	autoScroll : true,
	autoShow : true,
	collapsible : true,
	animate : true,
	border : false,
	rootVisible : false,
	split : true,
	width : 200,
	minSize : 175,
	maxSize : 400,
	title : '地区信息管理',
	layout : 'accordion',
	layoutConfig : {
		animate : true
	},		
	constructor: function(config) {
		this.root = new Ext.tree.AsyncTreeNode( {
			id : "root",
			text : "地区分类",
			"isWebnewscat" : "false",
			listeners : {
				'click' : function(node, event) {				
					node.expand(true);
				}
			},
			loader : new RockyCurd.TreeLoader( {
				dataUrl : "genAreaTree.action",
				expanded : true,
				nodeMeta : {
					id : 'id',
					text : 'showname'
				}
			})
		});
	
		config = Ext.apply({
			tbar : ['   ', {
				text : '添加',
				iconCls:'add',
				pressed : false,
				handler : this.create,
				scope : this
			}, '   ', {
				text : '修改',
				iconCls:'edit',			
				pressed : false,
				handler : this.edit,
				scope : this
			}, '   ', {
				text : '删除',
				iconCls:'remove',
				pressed : false,
				handler : this.removeData,
				scope : this
			}, '   ', {
				text : '刷新',
				iconCls:'refresh',
				pressed : false,
				handler : this.refresh,
				scope : this
			}, new Ext.Toolbar.Fill(), '   '],		
			root : this.root,
			listeners : {
				
			}		
		},config);
		AreaCurd.superclass.constructor.call(this, config);
		this.root.expand(true);
	},
	createForm : function() {
		this.tree=new Ext.tree.TreePanel( {		
				width:560,
				height:500,				
				border : false,
				rootVisible:true,
				autoScroll : true,			
				root : new Ext.tree.AsyncTreeNode( {
					id : "-1",
					text : "未归类",
					expanded : true,							
					loader : new RockyCurd.TreeLoader( {
						dataUrl : "genAreaTree.action",
						expanded : true,
						nodeMeta : {
							id : 'id',
							text : 'showname'
						}
					})
				}),
				listeners : {
					click : function( node,  e ) {
							var id = this.fp.findById('id').getValue();
							//var treeCombox = this.fp.form.items.item(2);
							var treeCombox = this.fp.find( "name", "parentName" )[0]
							var hidden = this.fp.find('name','parentId')[0];
							if(id){								
								if(id==node.id){	
									this.popwin.hide();	
									Ext.Msg.alert('提示','不能选自己为上级分类');
									return false;
								}
								if(node.parentNode){
									if(id==node.parentNode.id){		
										this.popwin.hide();	
										Ext.Msg.alert('提示','不能选自己的子分类为上级分类');
										return false;
									}
								}

							}
							treeCombox.setValue(node.text);								
							hidden.setValue(node.id);
							this.popwin.hide();						
							return true;
					},	
					scope:this
				}
			});		
		var formp = new Ext.form.FormPanel( {
			labelAlign : 'left',
			frame : false,
			title : '',
			bodyStyle : 'padding:5px 5px 0',		
			defaults : {
				width : 260
			},
			items : [{
						xtype : "hidden",
						name : "id",
						id : "id"
					},{
						name: "parentId",
						id: "parentId",	
						xtype : "hidden"
		   			},{
			          	xtype:"trigger",
						fieldLabel : "所属地区",
						allowBlank : false,
						emptyText : '请选择',						
						name : "parentName",						
						editable : false,	
						readOnly :true,
						onTriggerClick:function(e){
							if(!this.popwin){
								this.popwin=new Ext.Window({								  
									width:573,
									height:500,	
									autoScroll : false,
									title:'请选择上级地区',
									buttonAlign : "center",
									closeAction : "hide",
									modal : true,
									shadow : true,
									items : this.tree
								});
							}
							this.popwin.show(this);
							if (this.tree.rendered) {
								this.tree.root.reload();
								this.tree.root.expand(true);
							}							
						}.createDelegate(this)
									
					}, {
						xtype : 'textfield',
						fieldLabel : '地区名称',
						name : 'name',
						allowBlank : false
					}, {
						xtype : 'textfield',
						fieldLabel : '地区代码',
						name : 'code',
						allowBlank : true					
					}, {
						xtype : 'textarea',
						fieldLabel : '备注信息',
						name : 'memo',
						allowBlank : true
					}]
		});
		return formp;
	},
	edit : function() {
		var record = this.getSelectionModel(). getSelectedNode();
		if (!record) {
			Ext.Msg.alert("提示", "请先选择要编辑的行!");
			return;
		}
		this.showWin();
		this.fp.form.loadRecord(new Ext.data.Record(record.attributes,record.id));
		Ext.getDom('parentId').value= record.attributes.parentId;
	},
	refresh :function() {
		this.root.reload();
		this.root.expand(true);
	}
});